<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Jedrzej\Pimpable\PimpableTrait;
use Illuminate\Database\Eloquent\softDeletes;

class LiveRoom extends Model
{
    use HasFactory;
    use PimpableTrait;
    use SoftDeletes;

    /**
     *允许批量赋值的字段
     */
    public $fillable = [
        'room_id',
        'anchor_id',
        'name',
        'cover_img',
        'share_img',
        'error_msg',
        'mark',
        'sort',
    ];

    /**
     * 可搜索的字段
     */
    public $searchable = [
        'id',
        'room_id',
        'name',
        'is_show',
        'status',
        'is_openComments',
        'is_openShelf',
        'is_openLike',
        'live_status'
    ];

    /**
     *可排序字段
     */
    public $sortable = [
        'created_at',
        'id',
        'start_at',
        'status',
        'is_show',
        'is_openLike',
        'is_openShelf',
        'is_openComments',
        'replay_status',
    ];

    /**
     * 默认倒序
     */
    protected $defaultSortCriteria = ['id,desc'];

    /**
     * 直播间类型枚举
     */
    public  $roomTypeEnum = [
        'pushFlow' => '推流',
        'mobilePhone' => '手机直播',
    ];

    /**
     * 手机屏幕类型枚举
     */
    public  $screenTypeEnum = [
        'horizontalScreen' => '横屏',
        'verticalScreen' => '竖屏',
    ];

    /**
     * 直播状态枚举
     */
    public  $liveStatusEnum = [
        'liveBroadcast' => '直播中',
        'notStarted' => '未开始',
        'hasEnded' => '已结束',
        'noBroadcasting' => '禁播',
        'suspend' => '暂停',
        'abnormal' => '异常',
        'expired' => '已过期',
    ];

    /**
     * 审核状态枚举
     */
    public  $StatusEnum = [
        'notApproved' => '未审核',
        'wechatAudit' => '微信审核',
        'approved' => '审核通过',
        'auditFailed' => '审核未通过',
    ];

    /**
     * 关联主播模型
     */
    public function liveAnchor()
    {
        return $this->belongsTo(LiveAnchor::class, 'anchor_id', 'id');
    }

    /**
     * 多对多关联
     */
    public function liveProduct()
    {
        return $this->belongsToMany(LiveProduct::class, 'id', 'live_room_id', 'live_product_id');
    }

}
